package com.springboot.studentmanagedemo.service;

import com.springboot.studentmanagedemo.mapper.StudentMapper;
import com.springboot.studentmanagedemo.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: maihongyao, xudesheng
 * @createDate: 2021/12/6
 * @description: StudentService接口实现类
 */

@Service
public class StudentServiceImpl implements StudentService{

    /*
    @Autowired注解其实就是@Autowired(required = true)，用来注入已有的bean。但是有些时候，会注入失败
    所以修改为（required=false）
     */

    @Autowired(required = false)
    StudentMapper studentMapper;

    @Override
    public List<Student> query() {
        return studentMapper.query();
    }

    @Override
    public int updateStudent(Student student) {
        return studentMapper.update(student);
    }

    @Override
    public int insertStudent(Student student) {
        return studentMapper.add(student);
    }

    @Override
    public int deleteStudent(Integer studNo) {
        return studentMapper.deleteSt(studNo);
    }

    @Override
    public int deleteAllStudent(List<String> delList) {
        return studentMapper.delAllStudent(delList);
    }

    @Override
    @Cacheable(cacheNames = "studentByWhere")
    public List<Student> selectByStudNoAndSchool(Integer studNo, String school) {
        return studentMapper.queryByStudNoAndSchool(studNo,school);
    }
}
